<?php

	
$cuid=$_POST['CUID'];
$password=$_POST['password1'];
$fname=$_POST['firstName'];
$mname=$_POST['middleName'];
$lname=$_POST['lastName'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$zipcode=$_POST['zipCode'];
$cellnumber=$_POST['cellNumber'];
$sex=$_POST['sex'];
$deptid=$_POST['departmentName'];
$role='Professor';

$researchArea=$_POST['researchArea'];
$professorType=$_POST['professorType'];
$degree=$_POST['degree'];

$conn = oci_connect("gaurav", "gaurav", "xe"); 

$query = "INSERT INTO Candidate(CUID,Password,FName,MName,LName,Address1,Address2,City,State,Country,ZipCode,CellNumber,CreationDate,Sex,DeptID,Role) VALUES(:cuid,:password,:fname,:mname,:lname,:address1,:address2,:city,:state,:country,:zipcode,:cellnumber,SysDate,:sex,:deptid,:role)";

$query1 = "INSERT INTO Professor(CUID,ResearchArea,ProfessorType,Degree) VALUES(:cuid,:researcharea,:professortype,:degree)";

$bindargs1 = array();
array_push($bindargs1, array('CUID', $cuid, -1));
array_push($bindargs1, array('RESEARCHAREA', $researchArea, -1));
array_push($bindargs1, array('PROFESSORTYPE', $professorType, -1));
array_push($bindargs1, array('DEGREE', $degree, -1));

//echo 'Message'.$cuid.$password1.$fname.$mname.$lname.$address1.$address2.$city.$state.$country.$zipcode.$cellnumber.$sex.$deptid.$role;



$bindargs = array();
array_push($bindargs, array('CUID', $cuid, -1));
array_push($bindargs, array('PASSWORD', $password, -1));
array_push($bindargs, array('FNAME', $fname, -1));
array_push($bindargs, array('MNAME', $mname, -1));
array_push($bindargs, array('LNAME', $lname, -1));
array_push($bindargs, array('ADDRESS1', $address1, -1));
array_push($bindargs, array('ADDRESS2', $address2, -1));
array_push($bindargs, array('CITY', $city, -1));
array_push($bindargs, array('STATE', $state, -1));
array_push($bindargs, array('COUNTRY', $country, -1));
array_push($bindargs, array('ZIPCODE', $zipcode, -1));
array_push($bindargs, array('CELLNUMBER', $cellnumber, -1));
array_push($bindargs, array('SEX', $sex, -1));
array_push($bindargs, array('DEPTID', $deptid, -1));
array_push($bindargs, array('ROLE', $role, -1));

$r = db_execute_statement($conn, $query, $bindargs);
$r1 = db_execute_statement($conn, $query1, $bindargs1);

header('Location: /ViewAllProfessors.php');

function db_execute_statement($conn, $statement, $bindvars = array())
{
  $stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }
    // Bind parameters
  foreach ($bindvars as $b) {
    // create local variable with caller specified bind value 
    $$b[0] = $b[1];
    $r = oci_bind_by_name($stid, ":$b[0]", $$b[0], $b[2]);
    if (!$r) {
      db_error($stid, __FILE__, __LINE__);
    }
  }

  $r = oci_execute($stid);
  if (!$r) {
    db_error($stid, __FILE__, __LINE__);
  }
  return($r);
}
?>